package com.charley.icloud.admin.utils;

import java.util.Random;
import java.util.UUID;

/**
 * 随机账号生成
 * @author charley
 * @date 2024-04-28 14:16
 * */
public class RandomAccountGenerator {

    private static final Integer ACCOUNT_LENGTH = 9;

    public static String generateRandomAccount(){
        return RandomAccountGenerator.generateRandomAccount(ACCOUNT_LENGTH);
    }

    /**
     * 用于生成一个包含数字和小写字母的随机账号字符串
     * */
    public static String generateRandomAccount(Integer length) {
        Random random = new Random();
        StringBuilder account = new StringBuilder(length);
        for (int i = 0; i < length; i++) {
            // 随机生成字符：'0'到'9'或'a'到'z'
            int charIndex = random.nextInt(26);
            char randomChar = (char) ('a' + charIndex);
            account.append(randomChar);
        }
        return account.toString();
    }

    /**
     * UUID 模式 获取随机账号
     * @return 随机账号
     */
    public static String getAccountByUUID() {
        return UUID.randomUUID().toString().replaceAll("-", "").substring(0, ACCOUNT_LENGTH);
    }
}
